package io.github.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.mapper.Wrapper;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import io.github.dao.SysDepartDao;
import io.github.entity.SysDepartEntity;
import io.github.service.SysDepartService;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author: Max
 * @Date: 2019/10/9 10:09
 */

@Service
public class SysDepartServiceImpl extends ServiceImpl<SysDepartDao, SysDepartEntity> implements SysDepartService {

    @Resource
    private SysDepartDao dao;

    @Override
    public List<SysDepartEntity> listAll() {
        Wrapper<SysDepartEntity> wrapper = new EntityWrapper<>();
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<SysDepartEntity> listOrg() {
        Wrapper<SysDepartEntity> wrapper = new EntityWrapper<>();
        wrapper.eq("parent_id",0).or().eq("parent_id",1);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public List<SysDepartEntity> listDep(Integer orgId,String depName) {
        Wrapper<SysDepartEntity> wrapper = new EntityWrapper<>();
        if(StringUtils.isNotBlank(depName)){
            wrapper.like("name",depName);
        }
        wrapper.eq("parent_id",orgId);
        return baseMapper.selectList(wrapper);
    }

    @Override
    public void save(SysDepartEntity entity) {
        baseMapper.insert(entity);
    }

}
